import api from "../../api";

export default {
    async getIndexStoreData(ctx) {
        console.log(ctx);
        try {
            let data = await api.getIndexData(1, ctx.state.pageMuch)
            console.log(data);
            ctx.commit('setIndexStoreData', data)
            return data
        } catch (e) {
            return e.errMsg
        }
    },
    async getIndexStoreDataMore(ctx) {
        try {
            if (ctx.state.hasNoMore) {
                return
            }
            let page = ctx.state.data.length / ctx.state.pageMuch
            page = Number(page.toString().split('.')[0]) + 1
            let data = await api.getIndexData(page, ctx.state.pageMuch)
            if (data.rows.length < ctx.state.pageMuch) {
                ctx.state.hasNoMore = true
            }
            ctx.commit('addIndexStoreData', data.rows)
            return data
        } catch (e) {
            return e.errMsg
        }

    }
}